import simplejson, urllib

SERVICE = 'http://127.0.0.1:8000/service/%s/';

class LottoError (Exception):
    pass


class Lotto ():
    def __init__ (self, *args, **kwargs):
        self.id = kwargs.get ('id', args[0]);
        self.date = kwargs.get ('date', args[1]);
        self.nums = kwargs.get ('nums', args[2]);
    
    def __unicode__ (self):
        return u'Losowanie nr %i z dnia %s: %s' % (self.id, str(self.date), self.nums);


def client (mode = 'lotto'):
    url = SERVICE % mode;
    result = simplejson.load (urllib.urlopen (url));
    if 'Error' in result:
        raise LottoError;
    return result;

try:
    data = client ('mini');
    result = Lotto (data['id'], data['date'], data['nums']);
    print u'%s' % result;
except LottoError:
    print u'Nie poprawne dane!';
